package com.gjj.abox.account.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gjj.abox.account.viewHolder.CommonViewHolder;
import com.gjj.abox.account.viewHolder.RecyclerCommonViewHolder;

import java.util.List;

/**
 * Created by DWCloud on 2016/4/1.
 */
public abstract class RecyclerCommonAdapter<T> extends RecyclerView.Adapter<RecyclerCommonViewHolder> {
    protected LayoutInflater mInflater;
    protected Context mContext;
    protected List<T> mDatas;
    protected final int mItemLayoutId;

    public RecyclerCommonAdapter(Context context, List<T> mDatas, int itemLayoutId) {
        this.mContext = context;
        this.mInflater = LayoutInflater.from(mContext);
        this.mDatas = mDatas;
        this.mItemLayoutId = itemLayoutId;
    }

    @Override
    public RecyclerCommonViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(mItemLayoutId, null);
        return new RecyclerCommonViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerCommonViewHolder holder, int position) {
        convert(holder, mDatas.get(position));
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public abstract void convert(RecyclerCommonViewHolder helper, T item);

}
